package com.zenithmind.note.pojo.entity;

import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotNull;

/**
 * 评论点赞实体类
 * 遵循面向对象设计原则：
 * 1. 单一职责：只负责评论点赞关系的存储
 * 2. 不变性：点赞关系一旦建立，关键字段不可修改
 * 3. 数据完整性：确保点赞关系的唯一性
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(name = "评论点赞实体", description = "评论点赞实体")
public class CommentLike extends BaseEntity {

    @Schema(description = "评论ID")
    @NotNull(message = "评论ID不能为空")
    private String commentId;

    @Schema(description = "用户ID")
    @NotNull(message = "用户ID不能为空")
    private String userId;

    // ==================== 业务方法 ====================

    /**
     * 验证点赞记录是否有效
     *
     * @return 是否有效
     */
    public boolean isValid() {
        return this.commentId != null && !this.commentId.trim().isEmpty() &&
               this.userId != null && !this.userId.trim().isEmpty();
    }

    /**
     * 判断是否为指定用户对指定评论的点赞
     *
     * @param commentId 评论ID
     * @param userId 用户ID
     * @return 是否匹配
     */
    public boolean matches(String commentId, String userId) {
        return this.commentId != null && this.commentId.equals(commentId) &&
               this.userId != null && this.userId.equals(userId);
    }
}